package day09_GXJ;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/12
 */
public class Testjs {
    public static void main(String[] args) {
        ArrayList<js> list = new ArrayList<>();
        String username = "A2021牛";
        String password = "123456";
        Scanner sc = new Scanner(System.in);
        lsp:
        for (; ; ) {
            System.out.println("请输入你的用户名");
            String user1name = sc.nextLine();
            System.out.println("请输入你的密码");
            String pass1word = sc.nextLine();
            if (username.equals(user1name) && password.equals(pass1word)) {
                System.out.println("登录成功");
                break lsp;
            } else {
                System.out.println("你的用户名或者密码输入有误,请重新输入");
            }
        }
        System.out.println("欢迎来到五楼服务系统");
        loop:
        while (true) {
            System.out.println("请根据序号选择你要选择的选项");
            System.out.println("1 查看,2 删除,3 修改,4 添加 5 退出");
            String tell = sc.nextLine();
            switch (tell) {
                case "1":
                    System.out.println("查看");
                    print(list);
                    break;
                case "2":
                    System.out.println("删除");
                    deletejs(list);
                    break;
                case "3":
                    System.out.println("修改");
                    updatejs(list);
                    break;
                case "4":
                    System.out.println("添加");
                    print1(list);
                    break;
                case "5":
                    System.out.println("退出");
                    break loop;
                default:
                    System.out.println("如需特殊服务,请通知工作人员,带去小房间操作");
                    break;
            }

        }
    }

    private static void updatejs(ArrayList<js> list) {
        System.out.println("请输入你要修改的ID");
        Scanner sc = new Scanner(System.in);
        String IDs = sc.nextLine();//旧
        lo:
        for (int i = 0; i < list.size(); i++) {
            String IDSS = IDs;
            js sb1 = list.get(i);//旧
            String jID = sb1.getID();
            if (IDs.equals(jID)) {
                //新
                while (true) {
                    System.out.println("输入新的ID:");
                    sb1.setID(sc.nextLine());
                    int x = -1;
                    for (int j = 0; j < list.size(); j++) {
                        if (list.get(j).getID().equals(jID)) {
                            System.out.println("ID已存在!请重新输入:");
                            x = j;
                            break;
                        }
                    }
                    if (x == -1) {
                        System.out.println("请输入你要修改的姓名");
                        String name = sc.nextLine();
                        System.out.println("请输入你要修改的年龄");
                        String age = sc.nextLine();
                        list.get(i).setAge(age);
                        list.get(i).setName(name);
                        break lo;
                    }
                }
            } else {
                System.out.println("不存在技师!");
            }
        }
    }


    private static void deletejs(ArrayList<js> list) {

        System.out.println("请输入你要删除技师名字");
        Scanner sc = new Scanner(System.in);
        String names = sc.next();
        for (int i = 0; i < list.size(); i++) {
            js sb = list.get(i);
            String jname = sb.getName();
            if (names.equals(jname)) {
                list.remove(i);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println(names + "不存在,删除失败");
    }

    private static void print1(ArrayList<js> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入技师ID:");
        String ID = sc.next();
        System.out.println("请输入技师的姓名");
        String name = sc.next();
        System.out.println("请输入技师的年龄");
        String age = sc.next();
        js sb = new js(name, age, ID);
        list.add(sb);
        System.out.println("添加成功");
    }

    private static void print(ArrayList<js> list1) {
        if (list1.size() == 0) {
            System.out.println("技师都没有还开什么店.毁灭吧");
        } else {
            System.out.println("年龄\t 工号\t姓名");
            for (int i = 0; i < list1.size(); i++) {
                js j = list1.get(i);
                String jid = j.getID();
                String jage = j.getAge();
                String jname = j.getName();
                System.out.println(j.getAge() + " " + j.getID() + " " + j.getName());


            }
        }
    }

}
